﻿// JScript 文件

var GzList = null
var GzInfoList = null
var vCurAct = "AddGz"
var vCurGzId = 0
var vGzAct = "AddGzInfo"
var vCurGzInfoId = 0
function newGz()
{
    vCurAct = "AddGz"
    var vgzinfo = document.getElementById("gz_att")
    vgzinfo.style.display = "block"
    vgzinfo.style.left = document.documentElement.clientWidth/2-150 +"px"
    vgzinfo.style.top = 100 +"px"
    var vGzmc = document.getElementById("gzmc")
    vGzmc.disabled= false
}

function gzCancel()
{
    var vgzinfo = document.getElementById("gz_att")
    vgzinfo.style.display = "none"
    var vgzinfoatt = document.getElementById("gzinfo_att")
    vgzinfoatt.style.display = "none"
}

function gzConfirm(action, gzid)
{
    var vGzmc = document.getElementById("gzmc")
    var vGzms = document.getElementById("gzms")
    if (vGzmc.value == "")
    {
        alert("请输入规则名称")
        return
    }
    var vValue = vGzmc.value.split('|')
    var vParam = "_method="+action+"&major="+vValue[0]+"&minor="+vValue[1]+"&gzmc="+escape(vGzmc.childNodes[vGzmc.selectedIndex].text)+"&gzms="+escape(vGzms.value)+"&gzid="+gzid+"&pagesize="+GzList.pagesize
    var vData = CtnTrans.getText("/main.ashx?"+vParam);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
    }
    else
    {
        GzList.reset();
        GzList.insertXml(vData, 1);
        GzList.show();
    }
    gzCancel()
}


function InitGzList()
{
    GzList = new CtnListCtrl("GzList");
    GzList.create("gzgrid")
    GzList.pagesize = 10
    GzList.onGoPage = gotoPage
    GzList.onRowClick = onClickFun
    GzList.goPage(1);
    
    var vParam = '_method=GetRuleResList'
    var vXmlDoc = CtnTrans.getXml('/main.ashx', 'post', vParam);
    var vNode = vXmlDoc.selectNodes("items/item")
    for (var i = 0; i < vNode.length; ++i)
    {
        var vMajor = vNode[i].selectSingleNode("major")
        var vMinor = vNode[i].selectSingleNode("minor")
        var vNamec = vNode[i].selectSingleNode("namec")
        
        var vTmp = document.createElement("option")
        vTmp.value = $XML(vMajor)+"|"+$XML(vMinor)
        vTmp.text  = $XML(vNamec)
        $("gzmc").options.add(vTmp)
    }
    
}

function gotoPage(page)
{
    var serverUrl = "/main.ashx?_method=InitGz&pageno="+page+"&size="+GzList.pagesize
    var vData = CtnTrans.getText(serverUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
    }
    else
    {
        GzList.reset();
        GzList.insertXml(vData, 1);
        GzList.show();
    }
}

function editGz()
{
    if (GzList.selRow != -1)
    {
        vCurAct = "EditGz"
        var value = GzList.getRow(GzList.selRow).arrCell[0]
        var vParam = "_method=GetAGz&gzid="+value.text
        
        var vData = CtnTrans.getText('/main.ashx', 'post', vParam);
        if (!CtnError.validate(vData))
        {
            CtnError.show()
            return
        }
        
        var vgzinfo = document.getElementById("gz_att")
        vgzinfo.style.display = "block"
        vgzinfo.style.left = document.documentElement.clientWidth/2-150 +"px"
        vgzinfo.style.top = 100 +"px"
        var vGzmc = document.getElementById("gzmc")
        var vGzms = document.getElementById("gzms")
        var vXmlVal = CtnXML.getXmlDoc()
        vXmlVal.loadXML(vData)
        var vGzmcNodes = vXmlVal.selectNodes("item/gzmc")
        var vGzmsNodes = vXmlVal.selectNodes("item/gzms")

        //vGzmc.value = $XML(vGzmcNodes[0])
        for (var i = 0; i < vGzmc.length; ++i)
        {
            if (vGzmc.childNodes[i].text == $XML(vGzmcNodes[0]))
            {
                vGzmc.selectedIndex = i;
                break;
            }
        }
        vGzmc.disabled= true
        vGzms.value = $XML(vGzmsNodes[0])
        vCurGzId = value.text
    }
    
}

function deleGz()
{
    if (GzList.selRow != -1)
    {
        if (confirm("确定是否删除该规则"))
        {
            vCurAct = "DeleGz"
            var value = GzList.getRow(GzList.selRow).arrCell[0]
            var vParam = "_method=DeleGz&gzid="+value.text+"&pagesize="+GzList.pagesize
            var vData = CtnTrans.getText('/main.ashx', 'post', vParam);
            if (!CtnError.validate(vData))
            {
                CtnError.show()
            }
            else
            {
                GzList.reset();
                GzList.insertXml(vData, 1);
                GzList.show();
            }
        }
    }
}

function onClickFun(evt, colno)
{
    //获取规则详情
    vCurAct = "AddGz"
    vGzAct = "AddGzInfo"
    vCurGzInfoId = 0
    if (GzList.selRow != -1)
    {
         var value = GzList.getRow(GzList.selRow).arrCell[0]
         vCurGzId = value.text
         var vUrl = "/main.ashx?_method=getGzInfo&gzid="+value.text
         var vData = CtnTrans.getText(vUrl);
         if (!CtnError.validate(vData))
         {
             CtnError.show()
         }
         else
         {
             GzInfoList.reset();
             GzInfoList.insertXml(vData, 1);
             GzInfoList.show();
         }
    }
    
}

function newGzRec(gzid)
{
    vGzAct = "AddGzInfo"
    if (GzList.selRow != -1)
    {
        var vgzinfo = document.getElementById("gzinfo_att")
        vgzinfo.style.display = "block"
        vgzinfo.style.left = document.documentElement.clientWidth/2-150 +"px"
        vgzinfo.style.top = 150 +"px"
        
        var vUrl = "/main.ashx?_method=InitGzInfo&gzid="+gzid
        var vData = CtnTrans.getText(vUrl);
        if (!CtnError.validate(vData))
        {
            CtnError.show()
            return
        }
        
        var vXmlVal = CtnXML.getXmlDoc()
        vXmlVal.loadXML(vData)
        
        var vQyNodes = vXmlVal.selectNodes("ITEMS/QYTYPE/ITEM")
        var vMapNodes = vXmlVal.selectNodes("ITEMS/MAPTYPE/ITEM")
        var vSjQyNodes = vXmlVal.selectNodes("ITEMS/SJQYTYPE/ITEM")
        
        var i = 0;
        
        while ($("bj").hasChildNodes())
		{
			$("bj").removeChild($("bj").lastChild);
		}
        for (i = 0; i < vQyNodes.length; ++i)
        {
           var vTmp = document.createElement("option")
           vTmp.value = $XML(vQyNodes[i], "DBVALUE", "int");
           vTmp.text  = $XML(vQyNodes[i]);
           $("bj").options.add(vTmp)
        }
        
        while ($("txlx").hasChildNodes())
		{
			$("txlx").removeChild($("txlx").lastChild);
		}
        for (i = 0; i < vMapNodes.length; ++i)
        {
           var vTmp = document.createElement("option")
           vTmp.value = $XML(vMapNodes[i], "DBVALUE", "int");
           vTmp.text  = $XML(vMapNodes[i]);
           $("txlx").options.add(vTmp)
        }
        
        while ($("sj").hasChildNodes())
		{
			$("sj").removeChild($("sj").lastChild);
		}
        for (i = 0; i < vSjQyNodes.length; ++i)
        {
           var vTmp = document.createElement("option")
           vTmp.value = $XML(vSjQyNodes[i], "DBVALUE", "int");
           vTmp.text  = $XML(vSjQyNodes[i]);
           $("sj").options.add(vTmp)
        }
    }
}

function editGzRec(gzid)
{
    vGzAct = "EditGzInfo"
    if (GzInfoList.selRow != -1)
    {
         var vgzinfo = document.getElementById("gzinfo_att")
        vgzinfo.style.display = "block"
        vgzinfo.style.left = document.documentElement.clientWidth/2-150 +"px"
        vgzinfo.style.top = 150 +"px"
        
        var vUrl = "/main.ashx?_method=InitGzInfo&gzid="+vCurGzId
        var vData = CtnTrans.getText(vUrl);
        if (!CtnError.validate(vData))
        {
            CtnError.show()
            return
        }
        
        var vXmlVal = CtnXML.getXmlDoc()
        vXmlVal.loadXML(vData)
        
        var vQyNodes = vXmlVal.selectNodes("ITEMS/QYTYPE/ITEM")
        var vMapNodes = vXmlVal.selectNodes("ITEMS/MAPTYPE/ITEM")
        var vSjQyNodes = vXmlVal.selectNodes("ITEMS/SJQYTYPE/ITEM")
        
        var i = 0;
        var vXh = GzInfoList.getRow(GzInfoList.selRow).arrCell[2] //xh
        var vBj = GzInfoList.getRow(GzInfoList.selRow).arrCell[3] //qy
        var vSj = GzInfoList.getRow(GzInfoList.selRow).arrCell[4] //sj
        var vMap = GzInfoList.getRow(GzInfoList.selRow).arrCell[5] //map
         
        while ($("bj").hasChildNodes())
		{
			$("bj").removeChild($("bj").lastChild);
		}
        var vSelBj = null
        for (i = 0; i < vQyNodes.length; ++i)
        {
           var vTmp = document.createElement("option")
           vTmp.value = $XML(vQyNodes[i], "DBVALUE", "int");
           vTmp.text  = $XML(vQyNodes[i]);
           vTmp.selected =false
           if (vTmp.text == vBj.text)
           {
               vTmp.selected = "selected"
               vSelBj = vTmp.value
           }
           $("bj").options.add(vTmp)
        }
        $("bj").value = vSelBj
        while ($("txlx").hasChildNodes())
		{
			$("txlx").removeChild($("txlx").lastChild);
		}
		var vSelTx = null
        for (i = 0; i < vMapNodes.length; ++i)
        {
           var vTmp = document.createElement("option")
           vTmp.value = $XML(vMapNodes[i], "DBVALUE", "int");
           vTmp.text  = $XML(vMapNodes[i]);
           vTmp.selected =false
           if (vTmp.text == vMap.text)
           {
               vSelTx = vTmp.value;
               vTmp.selected = "selected"
           }

           $("txlx").options.add(vTmp)
        }
        $("txlx").value = vSelTx
        while ($("sj").hasChildNodes())
		{
			$("sj").removeChild($("sj").lastChild);
		}
		var vSelSj = null
        for (i = 0; i < vSjQyNodes.length; ++i)
        {
           var vTmp = document.createElement("option")
           vTmp.value = $XML(vSjQyNodes[i], "DBVALUE", "int");
           vTmp.text  = $XML(vSjQyNodes[i]);
           vTmp.selected =false
           if (vTmp.text == vSj.text|| (vTmp.text == "根节点" && vSj.text==""))
           {
               vSelSj= vTmp.value;
               vTmp.selected = "selected"
           }
           $("sj").options.add(vTmp)
        }
        $("sj").value = vSelSj
        $("xh").value = vXh.text;
    }
}


function deleGzRec(id)
{
    vGzAct = "DeleGzInfo"
    if (GzInfoList.selRow != -1)
    {
        if (confirm("确定是否删除该规则详情"))
        {
            var gzinfoid = GzInfoList.getRow(GzInfoList.selRow).arrCell[0]
            var gzid = GzInfoList.getRow(GzInfoList.selRow).arrCell[1]
            var vParam = "_method="+vGzAct+"&gzid="+gzid.text+"&gzinfoid="+gzinfoid.text
            var vData = CtnTrans.getText('/main.ashx', 'post', vParam);
            if (!CtnError.validate(vData))
            {
                CtnError.show()
            }
            else
            {
                GzInfoList.reset();
                GzInfoList.insertXml(vData, 1);
                GzInfoList.show();
            }
        }
    }
}

function InitGzInfoList()
{
    GzInfoList = new CtnListCtrl("GzInfoList");
    GzInfoList.create("gzinfoList")
    GzInfoList.onRowClick = onClickGzInfo
}

function onClickGzInfo()
{
    var vSel = GzInfoList.getRow(GzInfoList.selRow).arrCell[0];
    vCurGzInfoId = vSel.text
}

function gzInfoConfirm(e, id)
{
    var vBj = $F("bj")
    var vSj = $F("sj")
    var vTx = $F("txlx")
    var vXh = $F("xh")
    if (vBj == "" || vSj == "" || vTx == "" || vXh =="")
    {
        alert("请输入规则详情")
        return
    }
    
    var vParam = "_method="+e+"&gzid="+vCurGzId+"&bj="+escape(vBj)+"&sj="+escape(vSj)+"&txlx="+vTx+"&xh="+vXh+"&id="+id
    var vData = CtnTrans.getText("/main.ashx?"+vParam);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
    }
    else
    {
        GzInfoList.reset();
        GzInfoList.insertXml(vData, 1);
        GzInfoList.show();
    }
    gzCancel()
}